package org.gis.mapserver.manager;

import javax.annotation.Resource;
import org.common.service.DependenceManager;
import org.common.service.ServiceRegister;
import org.gis.mapserver.responsewriter.ResponseWriter;
import org.gis.mapserver.layer.Layer;
import org.gis.mapserver.layer.LayerFactory;
import org.gis.mapserver.rendercontext.RenderingContext;
import org.gis.mapserver.rendercontext.RenderingContextFactory;
import org.gis.mvc.bean.RequestBean;
import org.objective.base.MetaDataContainer;

/**
 *
 * @author gus
 */
public class SimpleProcessingManager implements ProcessingManager
{
    @Resource(name = "dependenceManager")
    private DependenceManager dependenceManager;

    @Resource(name = "renderingContextFactory")
    private RenderingContextFactory renderingContextFactory;
    
    @Resource(name = "layerFactory")
    private LayerFactory layerFactory;



    @Override
    public ResponseWriter processing(RequestBean requestBean) throws Exception
    {
        if (requestBean == null)
        {
            throw new IllegalArgumentException("requestBean");
        }

        MetaDataContainer metaDataContainer = MetaDataContainer.getInstance(ServiceRegister.getInstance(dependenceManager));
        metaDataContainer.loadMetaData();
        


        RenderingContext context = renderingContextFactory.createRenderingContext(requestBean);
        for (String layerName : requestBean.getLayerNames())
        {
            Layer layer = layerFactory.creatLayer(layerName, true);
            layer.render(context);
        }
        return context.getResponseWriter();
    }
}
